<?php
namespace app\admin\controller;

use think\Controller;
use think\Session;
use think\Request;
use app\admin\model\PartnerModel;

class Partner extends Common
{
	/**
	*	合伙人申请列表
	*/
	public function index()
	{
		$data = $this->request->param();
		$PartnerModel = new PartnerModel();
		$list = $PartnerModel->getPartner($data);
		// 获取分页显示
	    $page = $list->render();
	    $this->assign('page',$page);
		$this->assign('list',$list);

		$this->assign('u_name',isset($data['u_name']) ? $data['u_name'] : '');
		$this->assign('p_name',isset($data['p_name']) ? $data['p_name'] : '');
		$this->assign('p_card',isset($data['p_card']) ? $data['p_card'] : '');
		$this->assign('p_tel',isset($data['p_tel']) ? $data['p_tel'] : '');
		$this->assign('keyword',isset($data['keyword']) ? $data['keyword'] : '');
		$this->assign('p_status',isset($data['p_status']) ? $data['p_status'] : '');
		return $this->fetch();
	}

	/**
	*	修改合伙人申请信息
	*/
	public function edit()
	{
		$data = $this->request->param();

		if($data){
			$PartnerModel = new PartnerModel();
			$list = $PartnerModel->getOne($data['id']);
			$post = [];
			//把pc中的图片json转为数组
			$post = json_decode($list['p_pic'],true);
			$this->assign('post',$post);
			$this->assign('list',$list);
		}
		return $this->fetch();
	}

	/**
	*	修改合伙人申请信息提交
	*/
	public function editPost()
	{
		if ($this->request->isPost()) {
			$data = $this->request->param();

			$PartnerModel = new PartnerModel();

	        $list = $PartnerModel->editPartner($data['id'],$data);

	        $this->success('修改成功',url('/admin/Partner/index'));
        }
	}

	/**
	*	删除合伙人信息申请
	*/
	public function delete()
	{
		$data = $this->request->param();
		if($data){
			$PartnerModel = new PartnerModel();
			$list = $PartnerModel->deletePartner($data['id']);
			if($list){
				$this->success('删除成功',url('/admin/Partner/index'));

			}else{
				
				$this->error('删除失败',url('/admin/Partner/index'));	
			}
		}
	}

	/**
	*	合伙人申请福利列表
	*/
	public function welfare()
	{
		$PartnerModel = new PartnerModel();
		$list = $PartnerModel->getWelfare();
		$this->assign('list',$list);
		return $this->fetch();
	}

	/**
	*	添加合伙人申请福利
	*/
	public function addwelfare()
	{
		return $this->fetch();
	}

	/**
	*	添加合伙人申请福利提交
	*/
	public function addwelfarePost()
	{
		if ($this->request->isPost()) {
			$data = $this->request->param();

			$PartnerModel = new PartnerModel();

	        $list = $PartnerModel->addwelfare($data);

	        if ($list){
	        	$this->success('添加成功');
	        }else{
	        	$this->error('合伙人申请协议已存在,请不要重复添加');
	        }
        }
	}

	/**
	*	修改合伙人申请福利
	*/
	public function editwelfare()
	{
		$data = $this->request->param();
		$PartnerModel = new PartnerModel();
		$list = $PartnerModel->getOneWelfare($data['id']);
		$this->assign('list',$list);

		return $this->fetch();
	}

	/**
	*	修改合伙人申请福利提交
	*/
	public function editwelfarePost()
	{
		if ($this->request->isPost()) {
			$data = $this->request->param();

			$PartnerModel = new PartnerModel();

	        $list = $PartnerModel->editWelfarePost($data['id'],$data);

	        $this->success('修改成功');
        }

	}

	/**
	*	删除合伙人申请福利
	*/
	public function deletewelfare()
	{
		$data = $this->request->param();
		if($data){
			$PartnerModel = new PartnerModel();
			$list = $PartnerModel->deleteWelfare($data['id']);
			if($list){
				$this->success('删除成功',url('/admin/Partner/welfare'));

			}else{
				
				$this->error('删除失败',url('/admin/Partner/welfare'));	
			}
		}
	}

}